package com.study.experiment08.service.impl;

import com.study.experiment08.dao.IUserDao;
import com.study.experiment08.model.User;
import com.study.experiment08.service.IUserService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
public class UserServiceImpl implements IUserService {
    // 使用Hibernate实现持久层。
    private IUserDao userDao;

    //注入userDao
    public void setUserDao(IUserDao userDao) {
        this.userDao = userDao;
    }

    // 查找指定用户
    @Override
    public Boolean findUser(User user) {
        return userDao.find(user);
    }

    // 以ID查找用户
    @Override
    public User findUser(int id) {
        return userDao.find(id);
    }

    /*	 * 以Name查找用户	 */
    @Override
    public User findUserByName(String name) {
        return userDao.findUserByName(name);
    }

    // 查找所有用户
    @Override
    public List<User> findAllUser() {
        return userDao.findAll();
    }

    // 添加用户
    @Override
    public Boolean addUser(User user) {
        return userDao.insert(user);
    }

    // 更新（修改）用户
    @Override
    public Boolean updateUser(int id, User user) {
        return userDao.update(id, user);
    }

    // 删除指定用户
    @Override
    public Boolean deleteUser(int id) {
        return userDao.delete(id);
    }
}
